<?php

class M_menu extends Model{
		function M_menu(){
			parent::Model();	
		}
		function addmenu(){
			$this->load->database();
			$query_str = array(
					'menu_title' => $this->input->post('menu_title'),
					'menu_type' => $this->input->post('menu_sub'),
					'menu_link' => $this->input->post('menu_url'),
					'menu_statu_id' =>$this->input->post('menu_status'));
			return $this->db->insert('tbl_menu',$query_str);
		
		}
		
		// fun check the menu exists in database.........
		function checkexist($menu){
				$qu = "SELECT menu_title FROM tbl_menu WHERE menu_title = ? ";
				$result = $this->db->query($qu,$menu);
			if($result->num_rows() > 0){
				return true;
			}else{
				return false;
			}
		}
		// select account of users login----
		function select_menu($limit, $start){
			$this->db->limit($limit, $start);
			$this->db->select("*");
			$this->db->from('tbl_menu');
			$this->db->order_by('menu_title desc');

			return $this->db->get();
		}
		function  delete_data($oldrow){
			
			$this->db->delete('tbl_menu',$oldrow); 

			}
		//update account of users login by kimsong.kg@gmail.com..
		function update_menu($data){
			$id = $this->uri->segment(3);
			$this->db->select('*');
			$this->db->from('tbl_menu');
			$this->db->where('tbl_menu.menu_id',$id);
			
			return $this->db->get();

		}
		function menu_up(){
	
			$data = array(
				 'menu_title' => $this->input->post('menu_title'),
				 'menu_link' => $this->input->post('menu_link'),
				 'menu_type' => $this->input->post('menu_type'),
				 'menu_statu_id' =>$this->input->post('menu_status'),
					);
			$id = $this->input->post('getid');
			$this->db->where('menu_id',$id);
			return $this->db->update('tbl_menu',$data);
			}
		function StatusAction(){
		$setsta = $this->uri->segment(3);
		$getpro_id = $this->uri->segment(4);
		if($setsta == 1){
			 $data = array(
					'menu_statu_id' => '0' 
					);
			 $this->db->where('menu_id',$getpro_id );
			return $this->db->update('tbl_menu',$data);
			
			}else{
				$data = array(
					'menu_statu_id' => '1'
					);
				$this->db->where('menu_id',$getpro_id);
			return $this->db->update('tbl_menu',$data);
				}
		}
		
	}